package com.example.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.common.ResultStatus;
import com.example.pojo.Order;
import com.example.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@RestController
@CrossOrigin
public class OrderController {

    @Autowired
    private OrderService orderService;


    @PostMapping("/selectOrder")
    public  String selectOrder(JSONObject json){
        Integer userId=Integer.valueOf(json.getString("usrId"));
        List<Order> orderList= (List<Order>) orderService.selectOrder(userId);
        return json.toJSONString(orderList);
    }


    @PostMapping("/createOrder")
    public  String createOrder(JSONObject json){
        Order order=JSONObject.toJavaObject(json,Order.class);
        orderService.addNewOrder(order);
        return ResultStatus.SUCCESS.toString();
    }


}
